# -*- python -*-
# Copyright (C) 2003, Charles Wang.
# Author:  Charles Wang <charles@linux.net.cn>
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANT; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public LIcense for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.

import string
import os
import os.path

Import('env', 'mi_config', 'depInstall')

if 0:
    Command('mbconfig.conf', 'm4.mbconfig.conf',
            ' '.join(('m4 -Dmiinitrd_size=%d ' % 0, 
                      '-Dbootiso_fn=%s' % mi_config.bootiso_fn, 
                      '-Dkernelver=%s' % mi_config.mikernelver,
                      '-Dmiimages_cddir=%s' % mi_config.miimages_cddir, 
                      '-Ddistname=%s' % mi_config.distname, 
                      '-Dlangset=%s' % mi_config.langset, 
                      '-Dwelcome=\'%s\'' % mi_config.welcome, 
                      '-Ddrvfds=\'%s\'' % ''.join(map(lambda drvfd: '<drvfd>%s</drvfd>' % drvfd,
                                                      mi_config.kmods_arrange.keys())), 
                      '< $SOURCE > $TARGET', 
                     )))
else:
    # size of miinitrd is no longer fixed
    def gen_mbconfig_conf(env, target, source):
        cmd_line = ' '.join(['m4 -Dmiinitrd_size=%d' % \
                                File('#result/miinitrd').getsize(),
                             '-Dbootiso_fn=$bootiso_fn',
                             '-Dkernelver=$mikernelver',  
                             '-Dmiimages_cddir=$miimages_cddir',
                             '-Ddistname=$distname',
                             '-Dlangset=$langset',
                             '-Dwelcome=\'${welcome}\'',
                             '-Ddrvfds=\'%s\'' % \
                                ":".join(mi_config.kmods_arrange.keys()),
                             '-Dhotfixdir=$hotfixdir',
                             '< %s > %s' % (source[0], target[0])])
        return env.Execute(cmd_line)

    env.Command('mbconfig.conf', 'm4.mbconfig.conf', gen_mbconfig_conf)

    Depends('mbconfig.conf', '#result/miinitrd')

depInstall(env, 'mbroot_src',
           os.path.join(mi_config.mbdestdir, 'etc'),
           ['fstab', 'inittab', 'mdev.conf']) #, 'mbconfig.conf'])
